<template>
  <div id="components-form-demo-advanced-search" >
    <a-form class="ant-advanced-search-form" :form="form"  :label-col="{ span: 5 }" :wrapper-col="{ span: 8 }">

      <a-form-item label=""  >
        <span>姓　　名2 ：</span>
        <a-input v-decorator="['professorName']" :disabled="isNotChangeInfo"/>
      </a-form-item>
      <!--        <a-col :span="6">-->
      <!--          <a-form-item label="姓　　名" >-->
      <!--            <a-input v-decorator="['professorName']"/>-->
      <!--          </a-form-item>-->
      <!--        </a-col>-->
      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="6">-->
      <a-form-item label="">
        <span>性　　别 ：</span>
        <j-dict-select-tag type="list" v-decorator="['professorSex']" :disabled="isNotChangeInfo" :trigger-change="true" dictCode="sex" placeholder="请选择专家性别"/>
      </a-form-item>
      <!--        </a-col>-->
      <!--      </a-row>-->
      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="6">-->

      <!--        </a-col>-->
      <!--      </a-row>-->
      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="6">-->
      <!--          <a-form-item label="毕业院校">-->
      <!--            <j-dict-select-tag  type="list" v-decorator="['professorSchool']" :trigger-change="true" dictCode="sc" placeholder="请选择毕业院校"/>-->
      <!--&lt;!&ndash;            <a-input v-decorator="['professorSchool']" ref="searchVal" placeholder="请输入毕业院校" @keyup="selSchool"></a-input>&ndash;&gt;-->
      <!--          </a-form-item>-->
      <a-form-item label="">
        <span>毕业院校 ：</span>
        <!--            <j-tree-select-->
        <!--              v-model="schoolId"-->
        <!--              placeholder="请选择院校"-->
        <!--              dict="school,name,id"-->
        <!--              pidField="city"-->
        <!--              v-decorator="['professorSchool']">-->
        <!--            </j-tree-select>-->
        <a-input v-decorator="['professorSchool']" :disabled="isNotChangeInfo" placeholder="请输入毕业院校"></a-input>
      </a-form-item>
      <!--        </a-col>-->
      <!--      </a-row>-->
      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="6">-->
      <a-form-item label="">
        <span>所学专业 ：</span>
        <!--            <j-dict-select-tag type="list" v-decorator="['professorMajor']" :trigger-change="true" dictCode="school" placeholder="请选择所学专业"/>-->
        <!--            <a-form-item label="树形下拉测试">-->
        <j-tree-select
          v-model="marjorId"
          placeholder="请选择专业"
          dict="major,name,id"
          pidField="parentId"
          v-decorator="['professorMajor']" :disabled="isNotChangeInfo">
        </j-tree-select>
      </a-form-item>
      <!--          </a-form-item>-->
      <!--        </a-col>-->
      <!--      </a-row>-->

      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="6">-->

      <!--        </a-col>-->
      <!--      </a-row>-->
      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="6">-->
      <a-form-item label="">
        <span>学　　历 ：</span>
        <j-dict-select-tag type="list" v-decorator="['professorEducationBackground']" :disabled="isNotChangeInfo" :trigger-change="true" dictCode="education" placeholder="请选择学历"/>
      </a-form-item>
      <!--        </a-col>-->
      <!--      </a-row>-->
      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="6">-->
      <a-form-item label="">
        <span>学　　位 ：</span>
        <j-dict-select-tag type="list" v-decorator="['professorDegree']" :disabled="isNotChangeInfo" :trigger-change="true" dictCode="degree" placeholder="请选择学位"/>
      </a-form-item>
      <!--        </a-col>-->
      <!--      </a-row>-->
      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="8">-->
      <a-form-item label="">
        <span>工作单位 ：</span>
        <a-input v-decorator="['professorWorkUnit']" :disabled="isNotChangeInfo" placeholder="请输入工作单位"></a-input>
      </a-form-item>
      <!--        </a-col>-->
      <!--      </a-row>-->

      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="8">-->
      <a-form-item label="">
        <span>通讯地址 ：</span>
        <a-input v-decorator="['professorAddress']" :disabled="isNotChangeInfo" placeholder="请输入通讯地址"></a-input>
      </a-form-item>
      <!--        </a-col>-->
      <!--      </a-row>-->
      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="8">-->
      <a-form-item label="">
        <span>申报类别 ：</span>
        <j-category-select
          v-decorator="['professorDeclareCategory']" :disabled="isNotChangeInfo"
          pcode="B03"
          multiple
        />
      </a-form-item>
      <!--        </a-col>-->

      <!--      </a-row>-->

      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="6">-->
      <a-form-item label="">
        <span>职　　务 ：</span>
        <!--            <j-dict-select-tag type="list" v-decorator="['professorPosition']" :trigger-change="true" dictCode="position" placeholder="请选择职务"/>-->
        <a-input v-decorator="['professorPosition']" :disabled="isNotChangeInfo" placeholder="请输入职务"></a-input>
      </a-form-item>
      <!--        </a-col>-->
      <!--      </a-row>-->
      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="6">-->

      <!--        </a-col>-->
      <!--      </a-row>-->
      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="6">-->
      <a-form-item label="">
        <span>技术职称 ：</span>
        <j-dict-select-tag type="list" v-decorator="['professorTitle']" :disabled="isNotChangeInfo" :trigger-change="true" dictCode="job_title" placeholder="请选择技术职称"/>
      </a-form-item>
      <!--        </a-col>-->
      <!--      </a-row>-->

      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="6">-->
      <a-form-item label="">
        <span>从事专业 ：</span>
        <a-input v-decorator="['professorWorkMajor']" :disabled="isNotChangeInfo" placeholder="请输入从事专业"></a-input>
      </a-form-item>
      <!--        </a-col>-->
      <!--      </a-row>-->
      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="6">-->
      <a-form-item label="">
        <span>参加工作时间 ：</span>
        <j-date placeholder="请选择参加工作时间" v-decorator="['professorBeginWork']" :disabled="isNotChangeInfo" :trigger-change="true" />
      </a-form-item>
      <a-form-item label="">
        <span>从事专业时间 ：</span>
        <j-date placeholder="请选择从事专业时间" v-decorator="['professorMajorDate']" :disabled="isNotChangeInfo" :trigger-change="true"/>
      </a-form-item>
      <a-form-item label="">
        <span>出生年月 ：</span>
        <j-date placeholder="请选择出生年月" v-decorator="['professorBirthday']" :disabled="isNotChangeInfo" :trigger-change="true" />
      </a-form-item>
      <a-form-item  label="">
        <span>毕业时间 ：</span>
        <j-date placeholder="请选择毕业时间" v-decorator="['professorGraduateDate']" :disabled="isNotChangeInfo" :trigger-change="true"/>
      </a-form-item>
      <!--        </a-col>-->
      <!--      </a-row>-->
      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="6">-->
      <a-form-item label="">
        <span>身份证号 ：</span>
        <a-input v-decorator="['professorIdentity']" :disabled="isNotChangeInfo" placeholder="请输入身份证号"></a-input>
      </a-form-item>
      <!--        </a-col>-->
      <!--      </a-row>-->

      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="8">-->
      <a-form-item label="">
        <span>家庭地址 ：</span>
        <!--            <j-area-linkage type="cascader" v-decorator="['professorHomeAddress']" placeholder="请输入省市区"/>-->
        <a-input v-decorator="['professorHomeAddress']" :disabled="isNotChangeInfo" placeholder="请输入家庭地址"/>
      </a-form-item>
      <!--        </a-col>-->
      <!--      </a-row>-->
      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="8">-->
      <a-form-item label="">
        <span>健康状态 ：</span>
        <j-dict-select-tag type="list" v-decorator="['professorHealth']" :disabled="isNotChangeInfo" :trigger-change="true" dictCode="health" placeholder="请选择健康状况"/>
      </a-form-item>
      <!--        </a-col>-->
      <!--      </a-row>-->

      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="8">-->
      <a-form-item label="">
        <span>联系方式 ：</span>
        <a-input addon-before="办公室" v-decorator="['professorOfficeTel']" :disabled="isNotChangeInfo"/>
      </a-form-item>
      <!--        </a-col>-->
      <!--      </a-row>-->
      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="8">-->
      <a-form-item label="">
        <span>联系方式 ：</span>
        <a-input addon-before="手机" v-decorator="['professorPhone']" :disabled="isNotChangeInfo"/>
      </a-form-item>
      <!--        </a-col>-->
      <!--      </a-row>-->
      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="18">-->
      <a-form-item label="">
        <span>本人支持或参加过的典型项目（包括项目名称、建设规模、投资额及所负责的内容）</span>
        <a-textarea  :rows="4" v-decorator="['professorProjectIntroduce']" :disabled="isNotChangeInfo"/>
      </a-form-item>
      <!--        </a-col>-->
      <!--      </a-row>-->

      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="18">-->
      <a-form-item>
        <span>业务主管部门 ：</span>
        <a-textarea :rows="4" v-decorator="['professorLeadMsg']" :disabled="isNotChangeInfo"/>
      </a-form-item>
      <!--        </a-col>-->
      <!--      </a-row>-->

      <!--      <a-row :gutter="24">-->
      <!--        <a-col :span="18">-->
      <a-form-item >
        <span>行政审批局意见 ：</span>
        <a-textarea :rows="4" v-decorator="['professorApproveMsg']" disabled/>
      </a-form-item>
      <!--        </a-col>-->
      <!--      </a-row>-->
      <a-row>
        <!--isMultiple 多选 :wrapperCol="wrapperCol"  :labelCol="labelCol"-->
        <!--        <a-col :span="6" style="position: absolute; left: 76%">-->
        <a-col>
          <a-form-item label="个人照片" >
            <j-image-upload  v-decorator="['professorPhotoString']" :disabled="isNotChangeInfo"></j-image-upload>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <!--          <a-col :span="6" style="position: absolute; left: 75% ">-->
          <div>
            <a-form-item label="申请表照片">
              <j-image-upload  v-decorator="['professorInfoPhotoString']" :disabled="isNotChangeInfo"></j-image-upload>
            </a-form-item>
          </div>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <!--          <a-col :span="6" style="position: absolute; left: 75% ">-->
          <div>
            <a-form-item label="身份证复印件">
              <j-image-upload v-decorator="['professorIdString']" :disabled="isNotChangeInfo"></j-image-upload>
            </a-form-item>
          </div>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <!--          <a-col :span="6" style="position: absolute; left: 75% ">-->
          <div>
            <a-form-item label="个人承诺书">
              <j-image-upload v-decorator="['professorCommitmentString']" :disabled="isNotChangeInfo"></j-image-upload>
            </a-form-item>
          </div>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <!--          <a-col :span="6" style="position: absolute; left: 75% ">-->
          <div>
            <a-form-item label="个人工作简历">
              <j-image-upload multiple isMultiple showUploadList  v-decorator="['professorResumeString']" :disabled="isNotChangeInfo"></j-image-upload>
            </a-form-item>
          </div>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <!--          <a-col :span="6" style="position: absolute; left: 75% ">-->
          <div>
            <a-form-item label="学历、学位证书复印件">
              <j-image-upload multiple isMultiple showUploadList  v-decorator="['professorDegreeImageString']" :disabled="isNotChangeInfo"></j-image-upload>
            </a-form-item>
          </div>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <!--          <a-col :span="6" style="position: absolute; left: 75% ">-->
          <div>
            <a-form-item label="专业资格职业证书复印件">
              <j-image-upload multiple isMultiple showUploadList  v-decorator="['professorQualificationString']" :disabled="isNotChangeInfo"></j-image-upload>
            </a-form-item>
          </div>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <!--          <a-col :span="6" style="position: absolute; left: 75% ">-->
          <div>
            <a-form-item label="其他证明专业能力的材料">
              <j-image-upload multiple isMultiple showUploadList  v-decorator="['professorOtherString']" :disabled="isNotChangeInfo"></j-image-upload>
            </a-form-item>
          </div>
        </a-col>
      </a-row>

      <!--      <a-row>-->
      <!--        <a-col :span="18" :style="{ textAlign: 'right' }">-->
      <!--        </a-col>-->
      <!--      </a-row>-->

      <a-row>
        <a-col :span="18" :style="{ textAlign: 'right' }">
          <div v-show="isNotChangeInfo == false">
            <a-button type="primary" @click="handleOk" :style="{ marginRight: '8px' }">
              提交
            </a-button>
            <a-button :style="{ marginRight: '8px' }" @click="add">
              清除
            </a-button>
            <a :href="downLoadUrl" download="professorInfo.xlsx">
              <a-button type="primary"  icon="download" >
                点击下载附件
              </a-button>
            </a>
          </div>
          <div v-show="isNotChangeInfo == true">

            <div style="float: left;width: 10px">
            <QRcode></QRcode>
            </div>
            <div style="margin-left: 200px">
              <a :href="downLoadUrl" download="professorInfo.xlsx">
                <a-button type="primary"  icon="download" >
                  下载附件
                </a-button>
              </a>
            </div>
<!--
      <a :href="downLoadUrl" download="professorInfo.xlsx">
            <a-button type="primary"  icon="download" >
              点击下载附件
            </a-button>
          </a>
-->
          </div>
        </a-col>
      </a-row>

    </a-form>
  </div>

</template>

<script>
  import JDate from '@/components/jeecg/JDate'
  import JCategorySelect from '@/components/jeecg/JCategorySelect'
  import JTreeSelect from '@/components/jeecg/JTreeSelect'
  import pick from 'lodash.pick'
  import JAreaLinkage from '@comp/jeecg/JAreaLinkage'
  import ATextarea from "ant-design-vue/es/input/TextArea";
  import { httpAction } from '@/api/manage'
  import {downloadFile} from '@/api/manage'
  // 导入
  import {getAction} from '@/api/manage'
  import JImageUpload from '@/components/jeecg/JImageUpload'
  import ACol from "ant-design-vue/es/grid/Col";
  import QRcode from "./modules/QRcode";
  function getBase64(img, callback) {
    const reader = new FileReader();
    reader.addEventListener('load', () => callback(reader.result));
    reader.readAsDataURL(img);
  }
  export default {
    name:"DiyProfessorInfo",
    components:{
      ACol,
      ATextarea,
      JAreaLinkage,
      JTreeSelect,
      JImageUpload,
      JCategorySelect,
      JDate,
      JTreeSelect,
      downloadFile,
      QRcode
    },
    data() {
      return {
        schoolId:"",
        marjorId:"",
        form:this.$form.createForm(this),
        imageUrl: '',
        model:{},
        validatorRules:{

        },
        url:"/sendToDing2",
        downLoadUrl:'/professorInfo.xlsx',
        // 判断是否可以修改信息,默认不能为true
        isNotChangeInfo: true
      };
    },
    created(){
      this.select();
 /*     this.$notification.warning({
        message: '初次请先下载附件盖章后提交',
        description:
          '点击下载附件，打印后填写信息，有关部门盖章之后提交表单',
      })*/
    },
    mounted(){

    },
    methods: {
      select(){
        getAction("/org/diyProfessorInfo/queryByDingUserId").then((res) => {
          // 设置是否可以修改信息
          this.isNotChangeInfo = res.result.isChangeInfo == 0 ?true:false
            // 设置表单回显内容
          this.form.setFieldsValue({
            professorName:res.result.professorName,
            professorSex:res.result.professorSex,
            professorSchool:res.result.professorSchool,
            professorBirthday:res.result.professorBirthday,
            professorPhotoString:res.result.professorPhotoString,
            professorMajor:res.result.professorMajor,
            professorGraduateDate:res.result.professorGraduateDate,
            professorEducationBackground:res.result.professorEducationBackground,
            professorDegree:res.result.professorDegree,
            professorWorkUnit:res.result.professorWorkUnit,
            professorAddress:res.result.professorAddress,
            professorDeclareCategory:res.result.professorDeclareCategory,
            professorPosition:res.result.professorPosition,
            professorBeginWork:res.result.professorBeginWork,
            professorTitle:res.result.professorTitle,
            professorWorkMajor:res.result.professorWorkMajor,
            professorMajorDate:res.result.professorMajorDate,
            professorIdentity:res.result.professorIdentity,
            professorHomeAddress:res.result.professorHomeAddress,
            professorHealth:res.result.professorHealth,
            professorOfficeTel:res.result.professorOfficeTel,
            professorPhone:res.result.professorPhone,
            professorProjectIntroduce:res.result.professorProjectIntroduce,
            professorLeadMsg:res.result.professorLeadMsg,
            professorApproveMsg:res.result.professorApproveMsg,
            professorInfoPhotoString:res.result.professorInfoPhotoString,
            professorIdString:res.result.professorIdString,
            professorCommitmentString:res.result.professorCommitmentString,
            professorResumeString:res.result.professorResumeString,
            professorDegreeImageString:res.result.professorDegreeImageString,
            professorQualificationString:res.result.professorQualificationString,
            professorOtherString:res.result.professorOtherString,
          });
        });
      },
      selSchool(){
        let searchText=this.$refs.searchVal.value;
        console.log(searchText);
      },
      handleChange(info) {
        if (info.file.status === 'uploading') {
          this.loading = true;
          return;
        }
        if (info.file.status === 'done') {
          // Get this url from response in real world.
          getBase64(info.file.originFileObj, imageUrl => {
            this.imageUrl = imageUrl;
            this.loading = false;
          });
        }
      },
      beforeUpload(file) {
        const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
        if (!isJpgOrPng) {
          this.$message.error('您只能上传JPG文件!');
        }
        const isLt2M = file.size / 1024 / 1024 < 2;
        if (!isLt2M) {
          this.$message.error('图片必须小于2MB!');
        }
        return isJpgOrPng && isLt2M;
      },
      add () {
        console.log("进入add");
        this.edit({});
      },
      edit (record) {
        console.log("进入add"+record);
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          /**
           *  我添加的    ,'professorBirthday','professorSchool','professorMajor','professorGraduateDate','professorEducationBackground','professorDegree','professorWorkUnit'
           ,'professorAddress','professorPosition','professorBeginWork','professorTitle','professorWorkMajor','professorMajorDate','professorIdentity'
           */
          this.form.setFieldsValue(pick(this.model,'professorInfoPhotoString','professorPhotoString','professorDeclareCategory','professorName','professorSex','professorBirthday','professorSchool','professorMajor','professorGraduateDate','professorEducationBackground','professorDegree','professorWorkUnit'
            ,'professorAddress','professorPosition','professorBeginWork','professorTitle','professorWorkMajor','professorMajorDate','professorIdentity','professorHomeAddress',
            'professorOfficeTel','professorPhone','professorProjectIntroduce','professorLeadMsg','professorApproveMsg','professorHomeAddress','professorHealth'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },

      handleOk (){
        console.log("进入提交");
        const that = this;
        // 触发表单验证
        console.log("================"+this.model);
        this.form.validateFields((err, values) => {

          // 获取表单中type的id
          let formType = that.form.getFieldValue("professorDeclareCategory");
          // alert(formType);
          // 访问后台，查找hasChild
          let formRealType = "";
          let url = "/sys/category/findById?ids="+formType;
          console.log(url);
          getAction(url).then((res) => {
            if (res.success) {
              // alert("hasChild = " + res.result);
              formRealType = res.result;
              //  alert(formRealType==null)
              if(formRealType==0) {
                if (!err) {
                  console.log("进入提交状态");
                  console.log(err);
                  console.log(values);
                  let httpurl = '';
                  let method = '';
                  httpurl+=this.url;
                  method = 'post';
                  let formData = Object.assign(this.model, values);
                  console.log("表单提交数据",formData);
                  httpAction(httpurl,formData,method).then((res)=>{
                    console.log("res:"+res);
                    if(res.success){
                      console.log("res:"+res);
                      that.$message.success(res.message);
                      that.$emit('ok');
                    }else{
                      that.$message.warning(res.message);
                    }
                  }).finally(() => {
                    that.confirmLoading = false;
                    that.close();
                  })
                }
              }else{
                this.$message.error("请选择具体的申报类型！")
              }
            }
          });



        })
      }
    },
  };
</script>
<style>
  .ant-advanced-search-form {
    padding: 24px;
    background: #fbfbfb;
    border: 1px solid #d9d9d9;
    border-radius: 6px;
  }

  .ant-advanced-search-form .ant-form-item {
    display: flex;
  }

  .ant-advanced-search-form .ant-form-item-control-wrapper {
    flex: 1;
  }
  .avatar-uploader > .ant-upload {
    width: 128px;
    height: 128px;
  }
  .ant-upload-select-picture-card i {
    font-size: 32px;
    color: #999;
  }

  .ant-upload-select-picture-card .ant-upload-text {
    margin-top: 8px;
    color: #666;
  }

  #components-form-demo-advanced-search .ant-form {
    max-width: none;
  }
  #components-form-demo-advanced-search .search-result-list {
    margin-top: 16px;
    border: 1px dashed #e9e9e9;
    border-radius: 6px;
    background-color: #fafafa;
    min-height: 200px;
    text-align: center;
    padding-top: 80px;
  }
</style>